<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Sitealbum
 * @copyright  Copyright 2010-2011 BigStep Technologies Pvt. Ltd.
 * @license    http://www.socialengineaddons.com/license/
 * @version    $Id: widgetSettings.php 2011-08-026 9:40:21Z SocialEngineAddOns $
 * @author     SocialEngineAddOns
 */

$db = Zend_Db_Table_Abstract::getDefaultAdapter();

$db->query('INSERT IGNORE INTO `engine4_core_menuitems` ( `name`, `module`, `label`, `plugin`, `params`, `menu`, `submenu`, `enabled`, `custom`, `order`) VALUES
( "album_main_home", "sitealbum", "Albums Home", \'Album_Plugin_Menus::canViewAlbums\', \'{"route":"sitealbum_general","action":"index"}\', "album_main", "", 1, 0, 0),	( "sitealbum_quick_badge", "sitealbum", "Create Photos Badge", \'Sitealbum_Plugin_Menus::canCreateBadge\', \'{"route":"sitealbum_badge","action":"create","class":"buttonlink sitealbum_icon_badge_create"}\', "album_quick", "", 1, 0, 2);');

// Album Home Page
// page
// Check if it's already been placed
$select = new Zend_Db_Select($db);
$select
        ->from('engine4_core_pages')
        ->where('name = ?', 'sitealbum_index_index')
        ->limit(1);
$info = $select->query()->fetch();
if (empty($info)) {
  $db->insert('engine4_core_pages', array(
      'name' => 'sitealbum_index_index',
      'displayname' => 'Advanced Album Home',
      'title' => 'Advanced Album Home',
      'description' => 'This is album home page.',
      'custom' => 0
  ));
  $page_id = $db->lastInsertId('engine4_core_pages');

  // containers
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'main',
      'parent_content_id' => null,
      'order' => 2,
      'params' => '',
  ));
  $container_id = $db->lastInsertId('engine4_core_content');

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'right',
      'parent_content_id' => $container_id,
      'order' => 5,
      'params' => '',
  ));
  $right_id = $db->lastInsertId('engine4_core_content');

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'left',
      'parent_content_id' => $container_id,
      'order' => 4,
      'params' => '',
  ));
  $left_id = $db->lastInsertId('engine4_core_content');

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'top',
      'parent_content_id' => null,
      'order' => 1,
      'params' => '',
  ));
  $top_id = $db->lastInsertId('engine4_core_content');

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'middle',
      'parent_content_id' => $top_id,
      'order' => 6,
      'params' => '',
  ));
  $top_middle_id = $db->lastInsertId('engine4_core_content');

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'middle',
      'parent_content_id' => $container_id,
      'order' => 6,
      'params' => '',
  ));
  $middle_id = $db->lastInsertId('engine4_core_content');

// Top Middle
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.nevigation',
      'parent_content_id' => $top_middle_id,
      'order' => 3,
      'params' => '',
  ));
// Left
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.photo-of-the-day',
      'parent_content_id' => $left_id,
      'order' => 8,
      'params' => '{"title":"Photo of the Day"}',
  ));
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.list-popular-photos',
      'parent_content_id' => $left_id,
      'order' => 9,
      'params' => '{"title":"Most Liked Photos","itemCountPerPage":"4","popularType":"like","name":"sitealbum.list-popular-photos"}',
  ));

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.list-popular-photos',
      'parent_content_id' => $left_id,
      'order' => 10,
      'params' => '{"title":"Popular Photos","itemCountPerPage":"4","popularType":"view","name":"sitealbum.list-popular-photos"}',
  ));

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.list-popular-photos',
      'parent_content_id' => $left_id,
      'order' => 11,
      'params' => '{"title":"Most Commented Photos","itemCountPerPage":"4","popularType":"comment","name":"sitealbum.list-popular-photos"}',
  ));

// Middele
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.featured-photos-carousel',
      'parent_content_id' => $middle_id,
      'order' => 12,
      'params' => '{"title":"Featured Photos","vertical":"0", "noOfRow":"2","inOneRow":"3","interval":"250","name":"sitealbum.featured-photos-carousel"}',
  ));

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.list-photos-tabs-view',
      'parent_content_id' => $middle_id,
      'order' => 13,
      'params' => '{"title":"Photos","margin_photo":"12"}',
  ));

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.list-albums-tabs-view',
      'parent_content_id' => $middle_id,
      'order' => 14,
      'params' => '{"title":"Albums","margin_photo":"12"}',
  ));
  // Right Side
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.search-albums-form',
      'parent_content_id' => $right_id,
      'order' => 15,
      'params' => '[]',
  ));
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.featured-albums',
      'parent_content_id' => $right_id,
      'order' => 16,
      'params' => '{"title":"Featured Albums","itemCountPerPage":4}',
  ));

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.list-popular-albums',
      'parent_content_id' => $right_id,
      'order' => 17,
      'params' => '{"title":"Most Liked Albums","itemCountPerPage":"4","popularType":"like","name":"sitealbum.list-popular-albums"}',
  ));
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.list-popular-albums',
      'parent_content_id' => $right_id,
      'order' => 18,
      'params' => '{"title":"Popular Albums","itemCountPerPage":"4","popularType":"view","name":"sitealbum.list-popular-albums"}',
  ));
}

// Album View Page
// page
// Check if it's already been placed
$select = new Zend_Db_Select($db);
$select
        ->from('engine4_core_pages')
        ->where('name = ?', 'sitealbum_album_view')
        ->limit(1);
$info = $select->query()->fetch();

if (empty($info)) {
  $db->insert('engine4_core_pages', array(
      'name' => 'sitealbum_album_view',
      'displayname' => 'Advanced Album View Page',
      'title' => 'Advanced Album View Page',
      'description' => ' This is the main view page of an album.',
      'custom' => 0
  ));
  $page_id = $db->lastInsertId('engine4_core_pages');

  // containers
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'main',
      'parent_content_id' => null,
      'order' => 1,
      'params' => '',
  ));
  $container_id = $db->lastInsertId('engine4_core_content');

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'right',
      'parent_content_id' => $container_id,
      'order' => 5,
      'params' => '',
  ));
  $right_id = $db->lastInsertId('engine4_core_content');

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'middle',
      'parent_content_id' => $container_id,
      'order' => 6,
      'params' => '',
  ));
  $middle_id = $db->lastInsertId('engine4_core_content');



  // widgets entry

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.album-view',
      'parent_content_id' => $middle_id,
      'order' => 3,
      'params' => '{"title":"","titleCount":"true","itemCountPerPage":"40","margin_photo":"12"}',
  ));

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.inthis-album',
      'parent_content_id' => $right_id,
      'order' => 6,
      'params' => '{"title":"","titleCount":"true","itemCountPerPage":"3"}',
  ));

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.you-and-owner',
      'parent_content_id' => $right_id,
      'order' => 7,
      'params' => '{"title":"","titleCount":"true","itemCountPerPage":"2"}',
  ));
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.friends-photos',
      'parent_content_id' => $right_id,
      'order' => 8,
      'params' => '{"title":"","titleCount":"true","itemCountPhoto":"2"}',
  ));
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.friends-photo-albums',
      'parent_content_id' => $right_id,
      'order' => 9,
      'params' => '{"title":"","titleCount":"true","itemCountAlbum":"2","itemCountPhoto":"2"}',
  ));
}

// Photo View Page
// Check if it's already been placed
$select = new Zend_Db_Select($db);
$select
        ->from('engine4_core_pages')
        ->where('name = ?', 'sitealbum_photo_view')
        ->limit(1);
$info = $select->query()->fetch();

if (empty($info)) {
  $db->insert('engine4_core_pages', array(
      'name' => 'sitealbum_photo_view',
      'displayname' => 'Advanced Photo View Page',
      'title' => 'Advanced Photo View Page',
      'description' => '> This is the main view page of a photo.',
      'custom' => 0
  ));
  $page_id = $db->lastInsertId('engine4_core_pages');

  // containers
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'main',
      'parent_content_id' => null,
      'order' => 1,
      'params' => '',
  ));
  $container_id = $db->lastInsertId('engine4_core_content');

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'right',
      'parent_content_id' => $container_id,
      'order' => 5,
      'params' => '',
  ));
  $right_id = $db->lastInsertId('engine4_core_content');

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'container',
      'name' => 'middle',
      'parent_content_id' => $container_id,
      'order' => 6,
      'params' => '',
  ));
  $middle_id = $db->lastInsertId('engine4_core_content');



  // widgets entry
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.photo-view',
      'parent_content_id' => $middle_id,
      'order' => 3,
      'params' => '{"title":"","titleCount":"true"}',
  ));

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.list-popular-photos',
      'parent_content_id' => $right_id,
      'order' => 5,
      'params' => '{"title":"Popular Photos","titleCount":"true","itemCountPerPage":"4"}',
  ));

  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.list-recent-photos',
      'parent_content_id' => $right_id,
      'order' => 6,
      'params' => '{"title":"Recent Photos","titleCount":"true","itemCountPerPage":"4"}',
  ));
}

$select = new Zend_Db_Select($db);
// profile page
$select
        ->from('engine4_core_pages')
        ->where('name = ?', 'user_profile_index')
        ->limit(1);
$page_id = $select->query()->fetchObject()->page_id;


// sitealbum.profile-photos
// Check if it's already been placed
$select = new Zend_Db_Select($db);
$select
        ->from('engine4_core_content')
        ->where('page_id = ?', $page_id)
        ->where('type = ?', 'widget')
        ->where('name = ?', 'sitealbum.profile-photos');
$info = $select->query()->fetch();
if (empty($info)) {

  // container_id (will always be there)
  $select = new Zend_Db_Select($db);
  $select
          ->from('engine4_core_content')
          ->where('page_id = ?', $page_id)
          ->where('type = ?', 'container')
          ->limit(1);
  $container_id = $select->query()->fetchObject()->content_id;

  // middle_id (will always be there)
  $select = new Zend_Db_Select($db);
  $select
          ->from('engine4_core_content')
          ->where('parent_content_id = ?', $container_id)
          ->where('type = ?', 'container')
          ->where('name = ?', 'middle')
          ->limit(1);
  $middle_id = $select->query()->fetchObject()->content_id;

  // tab_id (tab container) may not always be there
  $select
          ->reset('where')
          ->where('type = ?', 'widget')
          ->where('name = ?', 'core.container-tabs')
          ->where('page_id = ?', $page_id)
          ->limit(1);
  $tab_id = $select->query()->fetchObject();
  if ($tab_id && @$tab_id->content_id) {
    $tab_id = $tab_id->content_id;
  } else {
    $tab_id = null;
  }

  // tab on profile
  $db->insert('engine4_core_content', array(
      'page_id' => $page_id,
      'type' => 'widget',
      'name' => 'sitealbum.profile-photos',
      'parent_content_id' => ($tab_id ? $tab_id : $middle_id),
      'order' => 4,
      'params' => '{"title":"Photos","titleCount":true}',
  ));
      //
    // Mobile Album Home
    // page
    // Check if it's already been placed
    $select = new Zend_Db_Select($db);
    $select
        ->from('engine4_core_pages')
        ->where('name = ?', 'sitealbum_mobi_index')
        ->limit(1);
    ;
    $info = $select->query()->fetch();

    if (empty($info)) {
      $db->insert('engine4_core_pages', array(
              'name' => 'sitealbum_mobi_index',
              'displayname' => 'Mobile Advanced Album Home',
              'title' => 'Mobile Advanced Album Home',
              'description' => 'This is the mobile verison of a album home page.',
              'custom' => 0
      ));
      $page_id = $db->lastInsertId('engine4_core_pages');

      // containers
      $db->insert('engine4_core_content', array(
              'page_id' => $page_id,
              'type' => 'container',
              'name' => 'main',
              'parent_content_id' => null,
              'order' => 1,
              'params' => '',
      ));
      $container_id = $db->lastInsertId('engine4_core_content');

      $db->insert('engine4_core_content', array(
              'page_id' => $page_id,
              'type' => 'container',
              'name' => 'middle',
              'parent_content_id' => $container_id,
              'order' => 2,
              'params' => '',
      ));
      $middle_id = $db->lastInsertId('engine4_core_content');

      // widgets entry
      $db->insert('engine4_core_content', array(
              'page_id' => $page_id,
              'type' => 'widget',
              'name' => 'sitealbum.nevigation',
              'parent_content_id' => $middle_id,
              'order' => 1,
              'params' => '',
      ));

      $db->insert('engine4_core_content', array(
              'page_id' => $page_id,
              'type' => 'widget',
              'name' => 'sitealbum.search-albums-form',
              'parent_content_id' => $middle_id,
              'order' => 2,
              'params' => '',
      ));
      $db->insert('engine4_core_content', array(
              'page_id' => $page_id,
              'type' => 'widget',
              'name' => 'sitealbum.list-photos-tabs-view',
              'parent_content_id' => $middle_id,
              'order' => 3,
              'params' => '{"title":"Photos"}',
      ));
      $db->insert('engine4_core_content', array(
              'page_id' => $page_id,
              'type' => 'widget',
              'name' => 'sitealbum.list-albums-tabs-view',
              'parent_content_id' => $middle_id,
              'order' => 4,
              'params' => '{"title":"Albums"}',
      ));
    }

}
?>
